﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SherlockGUI.CFG;

namespace SherlockGUI.Dlg
{
    public partial class SherlockCfgDlg : Form
    {
        public SherlockCfgDlg()
        {
            InitializeComponent();
        }

        private void SherlockCfgDlg_Load(object sender, EventArgs e)
        {
            textBox_SherlockPath.Text = GlobalCfg.m_SherlockCfg.strProgramPath;
            textBox_PicZoom.Text = GlobalCfg.m_SherlockCfg.dPicZoom.ToString("F2");
            checkBox_AutoRun.Checked = GlobalCfg.m_SysCfg.bAutoRun;
        }

        private void Cancel_Click(object sender, EventArgs e)
        {

        }

        private void OK_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;

            double dZoom = System.Convert.ToDouble(textBox_PicZoom.Text);
            if (dZoom < 0.0001)
            {
                dZoom = -1;
            }
            GlobalCfg.m_SherlockCfg.dPicZoom = dZoom;
            GlobalCfg.m_SysCfg.bAutoRun = checkBox_AutoRun.Checked;

            Close();
        }

        private void button_OpenSherlock_Click(object sender, EventArgs e)
        {
            //定义一个文件打开控件
            OpenFileDialog ofd = new OpenFileDialog();
            //设置打开对话框的初始目录，默认目录为exe运行文件所在的路径
            ofd.InitialDirectory = Application.StartupPath;
            //设置打开对话框的标题
            ofd.Title = "请选择要打开的文件";
            //设置打开对话框可以多选
            ofd.Multiselect = true;
            //设置对话框打开的文件类型
            ofd.Filter = "Sherlock|*.ivs|所有文件|*.*";
            //设置文件对话框当前选定的筛选器的索引
            ofd.FilterIndex = 2;
            //设置对话框是否记忆之前打开的目录
            ofd.RestoreDirectory = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                //获取用户选择的文件完整路径
                textBox_SherlockPath.Text = ofd.FileName;
            }
        }
    }
}
